<?php


namespace Admin\Controller;


class UserController extends CommonController{
    public function index(){

    }


    public function login(){
        if (IS_POST){
           $data=I('post.');
            $User = M("Administrators");
            if(empty($data['name'])){
                $this->ajaxReturn(['status'=>0,'msg'=>'用户名不能为空']);
            }
            if(empty($data['password'])){
                $this->ajaxReturn(['status'=>0,'msg'=>'密码不能为空']);
            }
            $UserInfo=$User->where("name='{$data['name']}'")->find();
            if($UserInfo['password']=md5($data['password'])){
                unset($UserInfo['password']);
                session('user_info',$UserInfo);
                $this->success('登录成功', U('Index/index'));
            }else{
                $this->ajaxReturn(['status'=>0,'msg'=>'登录失败，请稍后再试']);
            }
            
        }else{
          $this->display();
        }

    }
    /**
     * 用户注销
     */
    public function logout()
    {
        // 清楚所有session
        session(null);
        $this->ajaxReturn(['status'=>1,'msg'=>'退出成功','url'=>U('user/login')]);
    }
    public function register(){
        $User = M("Administrators"); // 实例化User对象
        $data['name'] = 'woddp';
        $data['email'] = '717563864@qq.com';
        $data['password'] = md5('s1208923150');
        $User->add($data);
    }
}